﻿namespace Furesoft.Styling.Design.Definition
{
    using System;
    using System.ComponentModel;
    using System.Drawing.Design;
    using System.Windows.Forms;
    using System.Windows.Forms.Design;

    internal class DefinitionStringEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if (svc != null)
            {
                var frm = new DefinitionEditor();

                if (value != null)
                {
                    frm.edit.Text = value.ToString();
                }

                if (frm.ShowDialog() == DialogResult.OK)
                {
                    value = frm.edit.Text;
                }
            }
            return value;
        }
    }
}